package com.scada.service.impl;

import java.util.List;
import java.util.Map;

import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import javax.jws.soap.SOAPBinding.Style;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.scada.dao.IPermissionDao;
import com.scada.inf.PermissionVisitor;
import com.scada.model.bean.Permission;
import com.scada.model.result.PageInfo;
import com.scada.model.result.ResponseBean;

@Service("permissionVisitorService")
@WebService
@SOAPBinding(style = Style.RPC)
public class PermissionVisitorImpl implements PermissionVisitor{

	@Autowired
	private IPermissionDao iPerDao;
	
	@Override
	public PageInfo<Permission> selectByPrimaryKey(PageInfo<Permission> pageInfo) {
		Permission permission = (Permission)pageInfo.getCondition();
		int count = iPerDao.count(permission);
		pageInfo.setRecordsTotal(count);
		List<Permission> pli = iPerDao.selectByPrimaryKey(pageInfo);
		pageInfo.setData(pli);
		return pageInfo;
	}

	@Override
	public Boolean validateIndex(Permission permission) {
		
		int i = iPerDao.validateIndex(permission);
		if(i > 0){
			return false;
		}
		return true;
	}

	@Override
	public ResponseBean deleteByPrimaryKey(Map<String,Object> map) {
		ResponseBean result = new ResponseBean();
		int i = iPerDao.deleteByPrimaryKey(map);
		if(i > 0 ){
			result.success("删除成功");
		}else{
			result.failed("删除失败");
		}
		return result;
	}

	@Override
	public ResponseBean insertSelective(Permission permission) {
		ResponseBean result = new ResponseBean();
		int i = iPerDao.insertSelective(permission);
		if(i > 0 ){
			result.success("新增成功");
		}else{
			result.failed("新增失败");
		}
		return result;
	}

	@Override
	public ResponseBean updateByPrimaryKeySelective(Permission permission) {
		
		ResponseBean result = new ResponseBean();
		int i = iPerDao.updateByPrimaryKeySelective(permission);
		if(i > 0 ){
			result.success("修改成功");
		}else{
			result.failed("修改失败");
		}
		return result;
	}

	@Override
	public Permission selectById(Map<String, Object> map) {
		
		return iPerDao.selectById(map);
	}

	@Override
	public List<Permission> getPermissionsName(Integer roleId) {
		
		return iPerDao.getPermissionsName(roleId);
	}

	@Override
	public List<Permission> getPermissionsCode(Integer roleId) {
		
		return iPerDao.getPermissionsCode(roleId);
	}

}
